<?php
    session_start();
    include_once ('inc/class/Util.class.php');
    $_SESSION['current_page'] = Util::getPage();
    include_once ('inc/class/User.class.php');
    include_once ('inc/class/Form.class.php');
    include_once ('inc/global/global.inc.php');
    include_once ('inc/code/head.php');

    if($_GET['op'] == 'immagine'){
        
    }
    if(isset($utente)){


?>
<div id="content">

    <div id="navProfile">
        
    </div>
    <br>
        <?php
            require ('inc/code/riepilogo.php');
        ?>
    <div id="under">
        <ul>
            <li><a href="profilo.php?action=profilo">Riepilogo</a></li>
            <li><a href="profilo.php?action=info">Altre info</a></li>
            <li><a href="profilo.php?action=modifica">Modifica</a></li>
            <li><a href="profilo.php?action=img">Modifica Immagine</a></li>
            <li><a href="profilo.php?action=ticket">Storico ticket</a></li>
            <?php
            if($utente->id_tipo_user == 4){
            ?>
            <li><a href="profilo.php?action=users">Utenti</a></li>
            <?php
            }
            ?>
        </ul>
        <?php
        if($_GET["action"] == "upload"){
        if($_FILES["fileName"]["error"]==UPLOAD_ERR_OK) {
        //Lo sposto dalla directory temporanea a quella voluta
        if(move_uploaded_file($_FILES['fileName']['tmp_name'],
        'img/profilo/' . $_FILES['fileName']['name'])) {
        echo("Upload eseguito con successo!");
//        var_dump($utente);
        $utente->change_image('img/profilo/'.$_FILES['fileName']['name']);
        $utente->immagine = 'img/profilo/'.$_FILES['fileName']['name'];
        }
        else {
        echo("Upload fallito!");
        unlink($_FILES['fileName']['tmp_name']);
        }
        }
        else {
        echo("Errore nell'upload! " . $_FILES['fileName']['error']);
        }

    }
        ?>

        <form enctype="multipart/form-data" method="post"action="?action=upload" >
            <input type="hidden" name="MAX_FILE_SIZE" value="3000000000">
            <input name="fileName" type="file">
            <input name="cmdGo" type="submit">
        </form>
        <?php 
            if($_GET["action"] == "info"){
                include ('inc/code/infoProfilo.php');
            }

            else if($_GET["action"] == "modifica"){
//                include ('inc/code/infoModifica.php');

            }
            else if($_GET["action"] == "ticket"){
                include ('inc/code/ticketStorico.php');
            }
            
            else if($_GET["action"] == "users"){
                include ('inc/code/assegnaRuoli.php');
            }

            if($_POST[registrazione])
            {
                echo "Qui";
            }
            
            
        ?>
        
    </div>
</div>

<?php
    include ('inc/code/footer.php');
    }
    else
        Util::logoutRedirect();
?>